/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package core.threads.client.inGame;
import core.messages.client.inGame.Msg_Skill_Cast;
import core.threads.client.Client_Public_Data;
import core.threads.client.Client_Public_MsgBox;
import cstAndEnum.SKILL_TYPE;
import models.CastInfo;
import models.Player;
import models.Skill.Skill;

/**
 *
 * @author Invince
 */
public class T_Client_Active_Skill  extends Thread{
/*----------Attributs-------------------*/
    protected boolean stop;
    protected boolean suspend;

/*----------Public functions------------*/
    @Override
    public void run() {
        /**-----Init-----**/
        String name;
        synchronized(Client_Public_Data.semaMyInfo){
           name=Client_Public_Data.myInfo.getName();
        }
        /**-----Loop----**/
        while(!this.stop){
            if(!this.suspend){
                if(!Client_Public_MsgBox.msgBox_Client_Skill_toCast.isEmpty()){
                    CastInfo castInfo=Client_Public_MsgBox.msgBox_Client_Skill_toCast.poll();
                    Player player=castInfo.getSource();
                    Skill skill=castInfo.getSkill();
                    SKILL_TYPE skillType=null;
                    if(player.getRole().getListSkill().contains(skill)){
                        skillType=SKILL_TYPE.NORMAL_SKILL;
                    }else if(player.getRole().getListMajestySkill().contains(skill)){//能不能出主公技在加入msgBox_Client_Skill_toCast时判断，另外还得控制按钮
                        skillType=SKILL_TYPE.MAJESTY_SKILL;
                    }
                    if(skillType!=null){//理论上不可能为null，控制一下skill是否为该role的skill
                        Msg_Skill_Cast msgSkillCast=new Msg_Skill_Cast(name, "server", skillType, castInfo);
                        Client_Public_MsgBox.msgBox_Client_Send_Msg.offer(msgSkillCast);
                    }
                }
            }
        }
        /**----End-----**/
    }

    public void stopT(){
        synchronized(this){
            this.stop=true;
        }
    }

    public void suspendT(){
        synchronized(this){
            this.suspend=true;
        }
    }

    public void resumeT(){
        synchronized(this){
            this.suspend=false;
        }
    }
/*----------Private functions-----------*/
/*----------Constructor-----------------*/
    public T_Client_Active_Skill() {
        synchronized(this){
            this.stop=false;
            this.suspend=false;
        }
    }
/*----------Gets and sets---------------*/
}
